package com.suse.warmstill.controller;

import com.suse.warmstill.common.model.ArticleCondition;
import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.common.model.ListPageModel;
import com.suse.warmstill.service.ArticleService;
import com.suse.warmstill.vo.ArticleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄靖
 * @author 2022-11-02 11:11
 * description:
 **/
@Api(tags = "wx端 文章")
@RestController
@RequestMapping("/wx/articles")
public class WXArticleApi {
    @Autowired
    private ArticleService articleService;

    @ApiOperation("首页  根据文章  分类，排序，筛选 进行 符合条件查询")
    @PostMapping("/indexlists")
    public CallResult<ListPageModel<ArticleVo>> lists(@RequestBody @Validated ArticleCondition condition) {

        ListPageModel<ArticleVo> pageModel = articleService.lists(condition);

        return CallResult.success(pageModel);
    }


    @ApiOperation("根据文章Id 查询文章详情")
    @GetMapping("/detail/{Id}")
    public CallResult<ArticleVo> articldetail(@PathVariable("Id") Long Id) {
        ArticleVo articleVo = articleService.articldetail(Id);

        return CallResult.success(articleVo);
    }


    @ApiOperation("点赞并且 返回 数量， status =0 表示点赞 1 表示取消点赞 ,2 表示 查询当前点赞数")
    @GetMapping("/praise")
    public CallResult praise(@RequestParam(value = "Articleid", required = true) Long articleId, @RequestParam("status") int status) {







        Long praiseCount = articleService.praise(articleId, status);





        return CallResult.success(praiseCount);
    }


    @ApiOperation("浏览量+1")
    @GetMapping("/addView/{articleId}")
    public CallResult<Long> addViewAccount(@PathVariable("articleId") Long articleId) {


        return CallResult.success(articleService.addViewAccount(articleId));
    }

    @ApiOperation("获取浏览量")
    @GetMapping("/getView")
    public CallResult<Long> getView(@RequestParam(value = "Articleid", required = true) Long articleId) {
        Long number = articleService.getView(articleId);
        return CallResult.success(number);
    }


    @ApiOperation("撤稿（删稿)")
    @GetMapping("/withdraw")
    public int withDraw(@RequestParam(value = "Articleid", required = true) Long articleId) {
        return articleService.withDraw(articleId);

    }


}
